﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using QuanLiThuVien.Source;

namespace QuanLiThuVien
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
       // private Source.clsTheDocGia m_tTheDocGia = new Source.clsTheDocGia();
        private string m_sMaNguoiDung;
        private XuLyThem m_cXuLyThem = new XuLyThem();
        private THUVIEN.Service1 serv = new THUVIEN.Service1(); 
       
        private void GioiHanQuyenNguoiDung()
        {           
            if (m_cXuLyThem.LoaiNguoiDung(m_sMaNguoiDung)=="DG")
            {
                TabMuonTra.Visibility = Visibility.Collapsed;
                TabQuanLi.Visibility = Visibility.Collapsed;
                TabHeThong.Visibility = Visibility.Collapsed;
            }
            if (m_cXuLyThem.LoaiNguoiDung(m_sMaNguoiDung) == "NV")
            {
                if (serv.SelectLoaiNhanVien_NhanVien(m_sMaNguoiDung) == "LNV768")
                {
                    TabMuonTra.Visibility = Visibility.Collapsed;
                    TabHeThong.Visibility = Visibility.Collapsed;
                    GroupDocGia.Visibility = Visibility.Collapsed;
                    GroupQuyDinh.Visibility = Visibility.Collapsed;
                    bntTimSachDG.Visibility = Visibility.Collapsed;
                }
                if (serv.SelectLoaiNhanVien_NhanVien(m_sMaNguoiDung) == "LNV9FD")
                {
                    TabHeThong.Visibility = Visibility.Collapsed;
                    bntTimSachDG.Visibility = Visibility.Collapsed;
                }
            }
            if (m_cXuLyThem.LoaiNguoiDung(m_sMaNguoiDung) == "ad")
            {
                TabNguoiDung.Visibility = Visibility.Collapsed;
                mnuItDoiMatKhau.Visibility = Visibility.Collapsed;
            }
        }

        public MainWindow(string MaDocGia)
        {
            InitializeComponent();
            // Insert code required on object creation below this point.
            m_sMaNguoiDung = MaDocGia;
            GioiHanQuyenNguoiDung();
            mainframe.NavigationService.Navigate(new ThongTinBanQuyen());
        }

        private void bntDocGia_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("TheDocGia.xaml", UriKind.Relative));
           // m_tTheDocGia.ShowListDocGia(QuanLiThuVien.TheDocGia.)
        }

        public void bntSach_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new ThongTinSach(m_sMaNguoiDung));
        }

        private void bntChoMuon_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("MuonSach.xaml", UriKind.Relative));
        }

        private void bntTimSach_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("TraCuu.xaml", UriKind.Relative));
        }

        private void bntXemQD_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("QuyDinh.xaml", UriKind.Relative));
        }

        private void bntTimSachDG_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("TraCuu.xaml", UriKind.Relative));
        }

        private void bntTraSach_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("TraSach.xaml", UriKind.Relative));
        }

        private void bntBaoCaoMS_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("BaoCaoMuonSach.xaml", UriKind.Relative));
        }

        private void bntBaoCaoTS_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("BaoCaoThongKeSachTraTre.xaml", UriKind.Relative));
        }

        private void mnuItDangXuat_Click(object sender, RoutedEventArgs e)
        {
            DangNhap m_fDangNhap = new DangNhap();
            m_fDangNhap.Show();
            this.Close();
        }

        private void bntThongTin_Click(object sender, RoutedEventArgs e)
        {
            if (m_cXuLyThem.LoaiNguoiDung(m_sMaNguoiDung)=="DG")
                mainframe.NavigationService.Navigate(new ThongTinDocGia(m_sMaNguoiDung));
            if(m_cXuLyThem.LoaiNguoiDung(m_sMaNguoiDung)=="NV")
                mainframe.NavigationService.Navigate(new ThongTinNhanVien(m_sMaNguoiDung));
        }

        private void bntSachMat_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("SachMat.xaml", UriKind.Relative));
        }

        private void bntSachHong_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("SachHong.xaml", UriKind.Relative));
        }

        private void bntDanhSachNV_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new Uri("DanhSachNhanVien.xaml", UriKind.Relative));
        }

        private void mnuItDoiMatKhau_Click(object sender, RoutedEventArgs e)
        {
            DoiMatKhau m_fDoiMatKhau = new DoiMatKhau(m_sMaNguoiDung);
            m_fDoiMatKhau.Show();
        }

        private void bntTroGiup_Click(object sender, RoutedEventArgs e)
        {
            mainframe.NavigationService.Navigate(new ThongTinBanQuyen());
        }
    }
}
